package cn.maxhou.aop;

import org.aspectj.lang.JoinPoint;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.Array;
import java.util.Arrays;

public class LoggerAspect {
    private static final Logger log = LoggerFactory.getLogger(LoggerAspect.class);

    /**
     * 前置增强-打印进入方法和参数
     */
    public void before(JoinPoint jp) {
        log.info("[LoggerAspect 前置增强] 正在调用{}的{}方法.方法入参:{}",
                jp.getTarget(),jp.getSignature().getName(),
                Arrays.toString(jp.getArgs()));
    }

    /**
     * 后置增强-打印返回结果
     */
    public void afterReturning(JoinPoint jp,Object result) {
        log.info("[LoggerAspect 后置增强]调用{}的{}方法.返回值:{}",
                jp.getTarget(),jp.getSignature().getName(),result);
    }
}
